Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

micromark-util-events-to-acorn

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micromark-util-events-to-acorn

micromark utility to try and parse events w/ acorn

  • 1.2.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1M
decreased by-39.49%
Maintainers
1
Weekly downloads
 
Created
Source

micromark-util-events-to-acorn

Build Coverage Downloads Size Sponsors Backers Chat

micromark utility to try and parse events with acorn.

Contents

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install micromark-util-events-to-acorn

In Deno with esm.sh:

import {eventsToAcorn} from 'https://esm.sh/micromark-util-events-to-acorn@1'

In browsers with esm.sh:

<script type="module">
  import {eventsToAcorn} from 'https://esm.sh/micromark-util-events-to-acorn@1?bundle'
</script>

Use

import {eventsToAcorn} from 'micromark-util-events-to-acorn'

// A factory that uses the utility:
/** @type {Tokenizer} */
function factoryMdxExpression(effects, ok, nok) {
  return start

  // …

    // …

    // Gnostic mode: parse w/ acorn.
    const result = eventsToAcorn(this.events.slice(eventStart), {
      acorn,
      acornOptions,
      start: pointStart,
      expression: true,
      allowEmpty,
      prefix: spread ? '({' : '',
      suffix: spread ? '})' : ''
    })

    // …

  // …
}

API

This module exports the identifier eventsToAcorn. There is no default export.

The export map supports the development condition. Run node --conditions development module.js to get instrumented dev code. Without this condition, production code is loaded.

eventsToAcorn(events, options)

Parameters
  • events (Array<Event>) — events
  • options (Options) — configuration
Returns

Result (Result).

Options

Configuration (TypeScript type).

Fields
  • acorn (Acorn, required) — typically acorn, object with parse and parseExpressionAt fields
  • acornOptions (AcornOptions, optional) — configuration for acorn
  • start (Point, optional) — place where events start
  • prefix (string, default: '') — text to place before events
  • suffix (string, default: '') — text to place after events
  • expression (boolean, default: false) — whether this is a program or expression
  • allowEmpty (boolean, default: false) — whether an empty expression is allowed (programs are always allowed to be empty)

Result

Result (TypeScript type).

Fields
  • estree (Program or undefined) — Program
  • error (Error or undefined) — error if unparseable
  • swallow (boolean) — whether the error, if there is one, can be swallowed and more JavaScript could be valid

Types

This package is fully typed with TypeScript. It exports the additional types Acorn, AcornOptions, Options, and Result.

Compatibility

Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 16+. Our projects sometimes work with older versions, but this is not guaranteed.

These extensions work with micromark version 3+.

Security

This package is safe.

Contribute

See contributing.md in micromark/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 14 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc